package com.gscitysfy.cus.drain.modules.command.service.impl;

import com.gscitysfy.cloudfrmwk.security.definition.core.HerodotusUserDetails;
import com.gscitysfy.cloudfrmwk.security.utils.SecurityUtils;
import com.gscitysfy.cus.drain.config.BusinessException;
import com.gscitysfy.cus.drain.modules.command.convert.DangerSituationManageConvert;
import com.gscitysfy.cus.drain.modules.command.convert.DrainDangerMsgPublishConvert;
import com.gscitysfy.cus.drain.modules.command.dto.DangerSituationManageDto;
import com.gscitysfy.cus.drain.modules.command.dto.DrainDangerMsgPublishDto;
import com.gscitysfy.cus.drain.modules.command.entity.DangerSituationManage;
import com.gscitysfy.cus.drain.modules.command.entity.DrainDangerMsgPublish;
import com.gscitysfy.cus.drain.modules.command.mapper.DrainDangerMsgPublishMapper;
import com.gscitysfy.cus.drain.modules.command.service.IDrainDangerMsgPublishService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Administrator
 * @since 2022-11-14 17:14:31
 */
@AllArgsConstructor
@Service
public class DrainDangerMsgPublishServiceImpl extends ServiceImpl<DrainDangerMsgPublishMapper, DrainDangerMsgPublish> implements IDrainDangerMsgPublishService {
    private final DrainDangerMsgPublishConvert drainDangerMsgPublishConvert;
    @Transactional(rollbackFor = Throwable.class)
    @Override
    public boolean saveOrUpdate(DrainDangerMsgPublishDto dto) {
        if (Objects.isNull(dto.getCmKid())) {
            DrainDangerMsgPublish drainDangerMsgPublish = new DrainDangerMsgPublish();
            drainDangerMsgPublishConvert.toEntity(drainDangerMsgPublish, dto);
            return this.save(drainDangerMsgPublish);
        } else {
            DrainDangerMsgPublish drainDangerMsgPublish  = baseMapper.selectById(dto.getCmKid());
            drainDangerMsgPublishConvert.toEntity(drainDangerMsgPublish, dto);
            return this.updateById(drainDangerMsgPublish);
        }
    }
}
